//
//  WLWelcomeViewController.swift
//  WLWeibo
//
//  Created by Devil on 16/8/13.
//  Copyright © 2016年 Wiliam. All rights reserved.
//

import UIKit
import SDWebImage
class WLWelcomeViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {()-> Void in
            self.view.layoutIfNeeded()
        }){(_)-> Void in
        
                UIView.animateWithDuration(0.25, animations: {()-> Void in
                    
                    self.messageLabel.alpha = 1
                    
                    }, completion: {(_)-> Void in
                
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION,object: nil)
                
                })
        
        }

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }

    private func setupUI(){
    
        view.addSubview(bgImageView)
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        bgImageView.snp_makeConstraints{(make)-> Void in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        headImageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
            
        }
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
    
    }
    
    
    private lazy var bgImageView: UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var headImageView: UIImageView = {

            let img = UIImageView(imgName: "avatar_default_big")
            img.wl_setImageWithString(WLUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
            img.layer.cornerRadius = 45
            img.layer.masksToBounds = true
            return img

}()
    
    private lazy var messageLabel: UILabel = {
    
        let label = UILabel()
        label.font = UIFont.systemFontOfSize(18)
        label.text = "欢迎回来"
        label.textColor = UIColor.darkGrayColor()
        label.textAlignment = .Center
        label.alpha = 0
   
        return label

    }()

}
